package com.RMP
{
    import flash.display.*;
    import flash.events.*;
    import flash.net.*;
    import flash.text.*;
    import flash.utils.*;
    import com.greensock.*;

    public class BookmarksNote extends Sprite
    {
        public var submitBtn:MovieClip;
        var fadeSpeed:Number;
        public var submitBG:MovieClip;
        public var input1:MovieClip;
        var myRoot:MovieClip;
        public var myMessage:TextField;
        public var myArrow:MovieClip;
        public var title1:TextField;
        public var mySubmit:TextField;

        public function BookmarksNote(param1:MovieClip, param2:Number, param3:String) : void
        {
            myRoot = param1;
            fadeSpeed = param2;
            submitBtn.buttonMode = true;
            submitBtn.useHandCursor = true;
            submitBtn.addEventListener(MouseEvent.CLICK, btnClick, false, 0, true);
            submitBtn.addEventListener(MouseEvent.ROLL_OVER, btnRollOver, false, 0, true);
            submitBtn.addEventListener(MouseEvent.ROLL_OUT, btnRollOut, false, 0, true);
            input1.input.htmlText = param3;
            input1.input.addEventListener(FocusEvent.FOCUS_IN, focusInListener, false, 0, true);
            myRoot.stage.addEventListener(Event.RESIZE, onResizer, false, 0, true);
            doResize();
            return;
        }

        function resetField() : void
        {
            myMessage.text = "";
            return;
        }

        public function fadeOutShell() : void
        {
            TweenMax.to(this, fadeSpeed, {alpha:0, overwrite:true, onComplete:function ()
            {
                visible = false;
                return;
            }
            });
            return;
        }

        function doResize() : void
        {
            title1.x = Math.round(4 * (myRoot.unitW + myRoot.gutterW));
            title1.y = Math.round(myRoot.headerH + 2 * (myRoot.unitH + myRoot.gutterH));
            var _loc_1:* = myRoot.unitW / 75;
            title1.scaleY = myRoot.unitW / 75;
            title1.scaleX = _loc_1;
            input1.x = Math.round(4 * (myRoot.unitW + myRoot.gutterW));
            input1.y = Math.round(myRoot.headerH + 2 * (myRoot.unitH + myRoot.gutterH) + 22 * (myRoot.unitW / 75));
            input1.inputBG.width = Math.round(663 * (myRoot.unitW / 75));
            input1.inputBG.height = Math.round(437 * (myRoot.unitW / 75));
            input1.input.width = 655;
            input1.input.height = 437;
            var _loc_1:* = myRoot.unitW / 75;
            input1.input.scaleY = myRoot.unitW / 75;
            input1.input.scaleX = _loc_1;
            var _loc_1:* = Math.round(4 * (myRoot.unitW + myRoot.gutterW));
            submitBtn.x = Math.round(4 * (myRoot.unitW + myRoot.gutterW));
            submitBG.x = _loc_1;
            var _loc_1:* = Math.round(input1.y + input1.height + 9 * (myRoot.unitW / 75));
            submitBtn.y = Math.round(input1.y + input1.height + 9 * (myRoot.unitW / 75));
            submitBG.y = _loc_1;
            var _loc_1:* = Math.round(108 * (myRoot.unitW / 75));
            submitBtn.width = Math.round(108 * (myRoot.unitW / 75));
            submitBG.width = _loc_1;
            var _loc_1:* = Math.round(26 * (myRoot.unitW / 75));
            submitBtn.height = Math.round(26 * (myRoot.unitW / 75));
            submitBG.height = _loc_1;
            mySubmit.x = Math.round(submitBG.x + 3);
            mySubmit.y = Math.round((submitBG.y + 1));
            var _loc_1:* = myRoot.unitW / 75;
            mySubmit.scaleY = myRoot.unitW / 75;
            mySubmit.scaleX = _loc_1;
            myArrow.x = Math.round(submitBG.x + submitBG.width - 10 * myRoot.unitW / 75);
            myArrow.y = Math.round(submitBG.y + 10 * myRoot.unitW / 75);
            myMessage.x = Math.round(6 * (myRoot.unitW + myRoot.gutterW));
            myMessage.y = mySubmit.y;
            var _loc_1:* = myRoot.unitW / 75;
            myMessage.scaleY = myRoot.unitW / 75;
            myMessage.scaleX = _loc_1;
            return;
        }

        function onResizer(event:Event)
        {
            doResize();
            return;
        }

        function btnRollOver(event:MouseEvent)
        {
            TweenMax.to(submitBG, fadeSpeed, {tint:myRoot.hotColor, overwrite:true});
            return;
        }

        function createComplete(event:Event) : void
        {
            var _loc_2:URLVariables = null;
            _loc_2 = new URLVariables(event.target.data);
            trace("create complete " + _loc_2);
            return;
        }

        function btnRollOut(event:MouseEvent)
        {
            TweenMax.to(submitBG, fadeSpeed, {tint:myRoot.coldColor, overwrite:true});
            return;
        }

        function btnClick(event:MouseEvent)
        {
            trace("input1.input.htmlText =  " + input1.input.htmlText);
            addNotes();
            myMessage.text = "Your note has been saved";
            setTimeout(resetField, 750);
            return;
        }

        function addNotes() : void
        {
            var _loc_1:String = null;
            var _loc_2:URLVariables = null;
            var _loc_3:URLRequest = null;
            var _loc_4:URLLoader = null;
            _loc_1 = myRoot.path + "/lightbox_support/addNote.php";
            _loc_2 = new URLVariables();
            _loc_2.lightbox_id = myRoot.myBookmarksID;
            _loc_2.note = input1.input.text;
            if (input1.input.text == "")
            {
                _loc_2.note = " ";
            }
            _loc_3 = new URLRequest(_loc_1);
            _loc_3.data = _loc_2;
            _loc_3.method = URLRequestMethod.POST;
            _loc_4 = new URLLoader();
            _loc_4.dataFormat = URLLoaderDataFormat.TEXT;
            _loc_4.addEventListener(Event.COMPLETE, createComplete);
            _loc_4.addEventListener(IOErrorEvent.IO_ERROR, sendIOError);
            _loc_4.load(_loc_3);
            return;
        }

        public function fadeInShell() : void
        {
            myRoot.menuShell.hRule3Off();
            visible = true;
            TweenMax.to(this, fadeSpeed, {alpha:1, delay:fadeSpeed, overwrite:true});
            return;
        }

        function focusInListener(event:FocusEvent) : void
        {
            if (stage.displayState == StageDisplayState.FULL_SCREEN)
            {
                myRoot.closeFullscreen();
            }
            return;
        }

        function sendIOError(event:IOErrorEvent) : void
        {
            trace("io error");
            return;
        }

    }
}
